package com.my.mvpdemo.mvp2.presenter;

import java.lang.ref.WeakReference;

/**
 * Created by 张英杰 on 2017/2/22.
 */

public class BasePresenter<T> {

    //弱引用当 内存不足时销毁
    //View引用 销毁
    protected WeakReference<T> mViewRef; //软引用 只要gc活动那么就会 销毁

    public void attachView(T view) {
        this.mViewRef = new WeakReference<T>(view);
    }

    public void detachView() {
        if (mViewRef != null) {
            mViewRef.clear();
        }
    }

    protected T getView(){
        return mViewRef.get();
    }
}
